<!DOCTYPE html>
<html lang = "en">
<head>
    <meta charset = "UTF-8">
    <title>Title</title>

    <!--=====================================================================-->
    <script>
        //定时器
        window.onload = function () {
            function showAlert() {
                alert('now');
            }
            //打开定时器
            // setInterval(showAlert,2000);    //一直执行; 参数1:执行的函数;    参数2:时间间隔(页面载入后开始计时)
            //setTimeout(showAlert,2000);      //只执行1次; 参数1:执行的函数;    参数2:时间间隔(页面载入后开始计时)

            //与btn进行绑定
            let oBtn1 = document.getElementById('btn1');
            let oBtn2 = document.getElementById('btn2');
            let timer = null;

            oBtn1.onclick = function () {
                timer = setInterval(showAlert,3000);
            };

            oBtn2.onclick = function () {
                clearInterval(timer);
            }
        };


        //获取当前日期时间
        let oDate = new Date();
        console.log(oDate.getHours());
        console.log(oDate.getMinutes());
        console.log(oDate.getSeconds());
        console.log(oDate.getMonth()+1);      //只有month需要+1,因为从java1.0抄来的时候有问题


    </script>
</head>

<body>

<div>
    <input type = "button" value="start" id="btn1">
    <input type = "button" value="stop" id="btn2">

</div>

</body>
</html>